package com.example.dairenkun.neufoodshop.adapter;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import android.widget.TextView;
import android.widget.Toast;

import com.example.dairenkun.neufoodshop.R;
import com.example.dairenkun.neufoodshop.activity.FoodDetailActivity;
import com.example.dairenkun.neufoodshop.bean.Buy;
import com.example.dairenkun.neufoodshop.bean.Food;
;
import com.example.dairenkun.neufoodshop.service.OrderService;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

;import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/3/6.
 */

public class SearchListAdapter extends RecyclerView.Adapter<ViewHolder> {
    int userid;
    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;
    public SearchListAdapter(Context mContext, List mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_search, parent, false);
        return new ViewHolder(v);


    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
      final Food entity = (Food) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.search_name.setText(entity.getFoodname());
        viewHolder.search_price.setText(entity.getPrice()+"元");
        viewHolder.search_intro.setText(entity.getIntro());
        if (!"".equals(entity.getPic()))
            Picasso.with(mContext).load(entity.getPic()).into(viewHolder.search_image);
        //点击进入详情
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext,FoodDetailActivity.class);
                intent.putExtra("food_id",entity.getFood_id()+"");
                mContext.startActivity(intent);

            }
        });

    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView search_name;
        ImageView search_image;
        TextView search_price;
        TextView search_intro;

        public ViewHolder(View itemView) {
            super(itemView);
            search_name = (TextView) itemView.findViewById(R.id.search_name);
            search_image = (ImageView) itemView.findViewById(R.id.search_image);
            search_price = (TextView) itemView.findViewById(R.id.search_price);
            search_intro = (TextView) itemView.findViewById(R.id.search_intro);

        }
    }

}
